<?php

namespace App\Console\Commands;

use App\Http\Controllers\GiftBagController;
use App\Http\Controllers\LoverController;
use App\Http\Controllers\MoonController;
use App\Http\Controllers\NationController;
use App\Http\Model\Config;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class NationActivity extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'nation:activity {all=0}';
    protected $liang_cache = 'NATION:LIANG:NUM';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '国庆活动';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->configModel = new Config();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $all = (int)$this->argument('all');
        if (0 === $all) {
            //查看靓号
            $this->getCache();
        } elseif (1 === $all) {
            //删除靓号
            $this->delCache();
        } elseif (3 === $all) {
            //入redis
            $this->liangNumCache();
        } elseif (5 === $all) {
            $this->getRank();
        } elseif (7 === $all) {
            //发奖励
            $this->awardGift();
        } elseif (10 === $all) {
            //生成用户积分记录
            $this->showScoreTuUser();
        }elseif (11 === $all) {
            //发放用户积分
            $this->rechargeScoreTuUser();
        }

    }

    private function liangNumCache()
    {
        $liang_cache = Redis::lrange($this->liang_cache, 0, -1);
        if (empty($liang_cache)) {
            $liang_str = "198888,196666,192222,195555,190000,190666,192333,196888,201999,222019,192000,192555,775888,246888,131444,111314,191000,192666,193000,194000,195000,196000,197000,198000,190111,190222,190333,190444,190555,190777,190888,365000,201900,201911,201922,201933,201944,201955,201966,201977,201988,201199,131499,131400,131411,131422,131433,131455,131466,131477,131488,221314,331314,441314,551314,661314,771314,881314,991314,110521,220521,330521,440521,550521,365066,365077,365088,365099,365366,212121,520520,521521,686868,168168,268268,886886,101101,966966,989898,365365,101010,242424,535353,120120,233233,110110,191919,654321,123456,456789,345678,234567,567567,135135,246246,789789,520365,191314,201314,520366";
            $liang_num = explode(',', $liang_str);
            shuffle($liang_num);
            for ($i = 0; $i < count($liang_num); $i++) {
                Redis::lpush($this->liang_cache, $liang_num[$i]);
            }
        }
    }

    private function getCache()
    {
        $liang_cache = Redis::lrange($this->liang_cache, 0, -1);
        dump($liang_cache);
    }

    private function delCache()
    {
        $liang_cache = Redis::lrange($this->liang_cache, 0, -1);
        for ($i = 0; $i < count($liang_cache); $i++) {
            Redis::lpop($this->liang_cache);
        }
    }

    private function awardGift()
    {
        $con = new NationController();
        return $con->awardGift();
    }


    private function getRank()
    {
        $con = new NationController();
        dd($con->getRankCache());
    }

    private function showScoreTuUser()
    {
        $con = new NationController();
        dd($con->scoreToUser());
    }

    private function rechargeScoreTuUser()
    {
        $con = new NationController();
        dd($con->rechargeDiamondToScore());
    }

}
